﻿using zijian666.WorkScheduler.Defines;

namespace zijian666.WorkScheduler.Abstractions;

/// <summary>
/// 表示一个工作管理器。
/// </summary>
public interface IWorkManager
{
    /// <summary>
    /// 获取待执行工作。
    /// </summary>
    Task<ICollection<WorkData>> GetPendingWorks(DateTimeOffset planTime, int limit, CancellationToken cancellation = default);

    /// <summary>
    /// 抢单
    /// </summary>
    /// <param name="ticket">工作凭证</param>
    /// <param name="work">工作实体</param>
    /// <param name="cancellation">取消标记</param>
    /// <returns>返回最新工作数据</returns>
    Task<WorkData> TryLock(string ticket, WorkData work, CancellationToken cancellation = default);

    /// <summary>
    /// 上报工作情况，并返回最新的工作数据。
    /// </summary>
    Task<WorkData> Report(WorkProgress progress, CancellationToken cancellation = default);

    /// <summary>
    /// 获取工作的最新数据
    /// </summary>
    WorkData GetWork(string id);
}